package uba.ing2.subite.services.impl;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;

import uba.ing2.subite.domain.LegalEntity;
import uba.ing2.subite.domain.PaidInvoice;
import uba.ing2.subite.services.PaymentRegistrationService;

/**
 * Implementación de {@link PaymentRegistrationService}, en esta prueba de concepto
 * los pagos se registran en memoria, en una versión final este servicio utilizaría una
 * base de datos.
 */
public class PaymentRegistrationServiceImpl implements PaymentRegistrationService {
	private Collection<PaidInvoice> paidInvoices = new ArrayList<PaidInvoice>();

	@Override
	public void register(PaidInvoice paidInvoice) {
		paidInvoices.add(paidInvoice);
	}

	@Override
	public Collection<PaidInvoice> findPaymentsByDate(LegalEntity busCompany, Date date) {
		Collection<PaidInvoice> result = new ArrayList<PaidInvoice>();

		for (PaidInvoice paidInvoice : paidInvoices) {
			if (paidInvoice.appliesTo(busCompany, date)) result.add(paidInvoice);
		}

		return result;
	}

	@Override
	public Collection<PaidInvoice> allPayments() {
		return paidInvoices;
	}
}
